package com.xm.conf;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicRabbitConfig {
    public static final String A = "topic.A";
    public static final String B = "topic.B";
    public static final String C = "topic.C";

    @Bean
    public Queue queueTA(){
        return new Queue(A);
    }

    @Bean
    public Queue queueTB(){
        return new Queue(B);
    }

    @Bean
    public Queue queueTC(){
        return new Queue(C);
    }

    @Bean
    TopicExchange topicExchange(){
        return new TopicExchange("topicExchange");
    }

    /**
     * 将队列A和主题交换机绑定，并指定路由键topic.A；队列A仅处理路由携带topic.A的消息
     */
    @Bean
    Binding bindingTopicA(){
        return BindingBuilder.bind(queueTA()).to(topicExchange()).with(A);
    }

    /**
     * 将队列B和主题交换机绑定，并指定路由键topic.B；队列B仅处理路由携带topic.B的消息
     */
    @Bean
    Binding bindingTopicB(){
        return BindingBuilder.bind(queueTB()).to(topicExchange()).with(B);
    }

    /**
     * 将队列C和主题交换机绑定，并指定路由键topic.*；队列C仅处理路由携带topic.*的消息
     */
    @Bean
    Binding bindingTopicC(){
        return BindingBuilder.bind(queueTC()).to(topicExchange()).with("topic.#");
    }

}
